// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import store from './store';
import 'element-ui/lib/theme-chalk/index.css';
import echarts from 'echarts'
import {has} from './common/js/btn_permission.js';

Vue.prototype.has = has;                    // 将 has 函数方法写到 vue 方法中,页面便可以直接调用此方法

Vue.use(ElementUI);

Vue.prototype.$echarts = echarts
Vue.config.productionTip = false

router.beforeEach((to, from, next) => {

	// 如果登录的情况下进入登录页路由直接跳到首页；其他页面直接进入
	if (localStorage.getItem("login") == 1) {
		store.commit('login', true);
	} else {
		store.commit('login', false);
	}

	if (store.state.isLogin) {
		if (to.path == '/login') {
			next({
				path:"/index"
			})
		} else{
			next()
		}
	} else {
	// 如果没有登录的情况下进入其他路由(非登录页)直接跳到登录页；输入登录页直接进入登录页
		if (to.path == '/login') {
			next()
		} else {
			next({
				path: "/login"
			})
		}

	}
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
